package com.gzz.orchid.context.application.rbac.convert;

import com.gzz.orchid.context.application.rbac.command.RoleSaveCmd;
import com.gzz.orchid.context.application.rbac.pojo.RoleDto;
import com.gzz.orchid.context.application.rbac.pojo.RoleVo;
import com.gzz.orchid.context.domain.rbac.entity.Permission;
import com.gzz.orchid.context.infrastructure.definition.Status;
import com.gzz.orchid.context.infrastructure.persistence.entity.sys.SysRolePo;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author higmd
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, imports = {Status.class})
public interface RoleConverter {
    RoleConverter INSTANCE = Mappers.getMapper(RoleConverter.class);

    @Mappings({
            @Mapping(target = "status", expression = "java(Status.parse(po.getStatus()))"),
            @Mapping(target = "permissions", source = "permissions"),
    })
    RoleVo mapVo(SysRolePo po, List<Permission> permissions);

    @Mappings({
            @Mapping(target = "status", expression = "java(Status.parse(po.getStatus()))")
    })
    RoleDto mapDto(SysRolePo po);

    //
    void updatePo(@MappingTarget SysRolePo po, RoleSaveCmd cmd);
}
